package com.xishu.controller;

import com.xishu.entity.shop.ShopSearchItem;
import com.xishu.response.ResponseData;
import com.xishu.response.VerifyUtil;
import com.xishu.service.CommonService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashSet;
import java.util.List;

import static com.xishu.config.Constant.SHOP_SEARCH_DELETE_ITEM;
import static com.xishu.config.Constant.SHOP_SEARCH_ITEM;

@RestController
public class ShopSearchItemController {
    private CommonService commonService = CommonService.getInstance();

    @ApiOperation(value = "报表里面的查询字段，1菜品，2品类，3支付方式，4服务员，5删除菜品,前端在显示的时候需要去重")
    @PutMapping(value = ("/init/report/search/condition"), produces = ("application/json;charset=UTF-8"))
    public ResponseData search(@RequestBody ShopSearchItem shopSearchItem) throws Exception {
        VerifyUtil.verify(() -> shopSearchItem.getType() != null);
        VerifyUtil.verify(() -> shopSearchItem.getType() >= SHOP_SEARCH_ITEM && shopSearchItem.getType() <= SHOP_SEARCH_DELETE_ITEM);
        shopSearchItem.setPageSize(999);

        List<ShopSearchItem> shopSearchItems = commonService.searchAll(shopSearchItem);
        return commonService.createResponse(new HashSet<>(shopSearchItems));
    }
}
